<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set value="<%=request.getContextPath()%>" var="ctx"></c:set>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="Content-Type" content="multipart/form-data; charset=utf-8">
	<meta name="keywords" content="关键字台">
    <meta name="description" content="描述"> 
    <link href="${ctx}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx}/css/animate.css" rel="stylesheet">
    <link href="${ctx}/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="${ctx}/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet"> 
	<link href="${ctx}/css/plugins/toastr/toastr.min.css" rel="stylesheet" >
	<title>摇一摇奖品配置</title>
<!-- Web Uploader -->

</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
           <div class="col-sm-12">
           		<div class="ibox float-e-margins">
           			<div class="ibox-title">
                        <div class="row">
                           <div class="col-sm-10">
                                <h3>摇一摇奖品配置</h3>
                           </div>
                           
                        </div>
                      </div>
            
	            <div class="ibox-content">
	            	<div class="row">
                        <div class="col-sm-3">
                             <div class="form-group">
		                         <div class="input-group">
		                             <div class="input-group-addon">奖品类型</div>
		                           	 <select class="form-control input-lg" id="type_" name="type_" onchange="findYYYConfig();">
		                           	 	<c:if test="${type == 1 }">
											<option value="1">实物</option>
											<option value="2">红包</option>
											<option value="3">积分</option>								
		                           	 	</c:if>
		                           	 	<c:if test="${type == 2 }">
											<option value="2">红包</option>
											<option value="1">实物</option>
											<option value="3">积分</option>								
		                           	 	</c:if>
		                           	 	<c:if test="${type == 3 }">
											<option value="3">积分</option>								
											<option value="1">实物</option>
											<option value="2">红包</option>
		                           	 	</c:if>
		                             </select>                                         
		                          </div>
		                    </div>
                        </div>
                        <div class="col-sm-7">
                             
                         </div>
                         <div class="col-sm-2">
                             <div class="ibox-tools">
								<button type="button" class="btn btn-success btn-block" style="color:#fff" onclick="addPrizesModal();return false;">新增奖品</button>
                             </div>
                         </div>
                     </div>
	                </div>
	                  

          	<!-- 奖品信息 -->
	         <div class="ibox-content" style="display:none;" id="tableDiv">
				<table class="table table-striped table-bordered table-hover dataTables-example text-center" >
                    <thead>
                        <tr id="tr">
                            <th class="text-center">序号</th>
                            <th class="text-center">名称</th>
                            <th class="text-center">金额</th>
                            <th class="text-center">数量</th>
                            <th class="text-center">中奖概率</th>
                            <th class="text-center">操作</th>
                        </tr>
                    </thead>
                    <tbody id="tbody">                         
                    </tbody>
                </table>
			</div>
			</div> 
		 </div>
	</div>
	</div>
	<!-- 删除 -->
	<div class="modal inmodal fade" id="delModal" tabindex="-1"
		role="dialog" aria-hidden="true">
		<div class="modal-dialog modal-sm">
			<div class="modal-content">
				<div class="modal-body">
					<h3>确认删除该条奖品记录么？</h3>
				</div>
				<div class="modal-footer">
					<form class="form-horizontal" id="delPrizes" method="post">
						<input type="hidden" name="id" id="delPrizesId" />
						<button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary" data-flg="0">确认</button>
					</form>
				</div>
			</div>
		</div>
	</div>
	
	<!-- 实物 -->
	<div class="modal inmodal in" id="addModal" tabindex="-1" role="dialog"
		aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content animated fadeIn">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">×</span><span class="sr-only">Close</span>
					</button>
					<h2 class="modal-title">新增奖品信息</h2>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="addPrizesForm" method="POST">
						<input type="hidden" class="form-control" name="amount" id="amount"
										value="0" style="text-align: right;">
						<div class="form-group">
							<label class="col-sm-3 control-label">奖品名称：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" name="name" maxlength='50'>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">奖品类型：</label>
							<div class="col-sm-8">
								<select class="form-control input-lg" id="addType_" name="type" onchange="changeAddModal();">		                           	 	
									<option value="1">实物</option>
									<option value="2">红包</option>
									<option value="3">积分</option>								                           	 	
		                         </select>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">奖品数量：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" name="num" maxlength='11'>
							</div>
						</div>
						<div class="form-group" id="hb" style="display:none;">
							<label class="col-sm-3 control-label">红包金额：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" name="hb" maxlength='11'>
							</div>
						</div>
						<div class="form-group" id="jf" style="display:none;">
							<label class="col-sm-3 control-label">中奖积分：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" name="jf" maxlength='11'>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">中奖概率：</label>
							<div class="col-sm-8">
								<div class="input-group">
									<input type="text" class="form-control" name="rate" id="rate" maxlength='8'
										value="0" style="text-align: right;"> <span
										class="input-group-addon">%</span>
								</div>
							</div>
						</div>
						
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" data-flg="0">保存</button>
				</div>
			</div>
		</div>
	</div>
	
	<!-- 实物 -->
	<div class="modal inmodal in" id="swModal" tabindex="-1" role="dialog"
		aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content animated fadeIn">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">×</span><span class="sr-only">Close</span>
					</button>
					<h2 class="modal-title">实物奖品信息</h2>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="updPrizes" method="POST">
						<input type="hidden" class="form-control" name="id" id="updPrizesId">
						<input type="hidden" class="form-control" name="type" id="updPrizesType">
						<input type="hidden" class="form-control" name="amount" id="amount"
										value="0" style="text-align: right;">
						<div class="form-group">
							<label class="col-sm-3 control-label">奖品名称：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" name="name" maxlength='50'>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">奖品数量：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" name="num" maxlength='11'>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">中奖概率：</label>
							<div class="col-sm-8">
								<div class="input-group">
									<input type="text" class="form-control" name="rate" id="rate" maxlength='8'
										value="0" style="text-align: right;"> <span
										class="input-group-addon">%</span>
								</div>
							</div>
						</div>
						
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" data-flg="0">保存</button>
				</div>
			</div>
		</div>
	</div>
	
	<!-- 红包-->
	<div class="modal inmodal in" id="hbModal" tabindex="-1" role="dialog"
		aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content animated fadeIn">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">×</span><span class="sr-only">Close</span>
					</button>
					<h2 class="modal-title">红包奖品信息</h2>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="updHBPrizes" method="POST">
						<input type="hidden" class="form-control" name="id" id="updHBPrizesId">
						<input type="hidden" class="form-control" name="type" id="updHBPrizesType">
						<div class="form-group">
							<label class="col-sm-3 control-label">奖品名称：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" name="name" maxlength='50'>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">奖品数量：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" name="num" maxlength='11'>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">红包金额(元)：</label>
							<div class="col-sm-8">
									<input type="text" class="form-control" name="amount" id="amount"
										maxlength='8' >
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">中奖概率：</label>
							<div class="col-sm-8">
								<div class="input-group">
									<input type="text" class="form-control" name="rate" id="rate" maxlength='8'
										value="0" style="text-align: right;"> <span
										class="input-group-addon">%</span>
								</div>
							</div>
						</div>
						
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" data-flg="0">保存</button>
				</div>
			</div>
		</div>
	</div>
	
	<!-- 积分-->
	<div class="modal inmodal in" id="jfModal" tabindex="-1" role="dialog"
		aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content animated fadeIn">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">×</span><span class="sr-only">Close</span>
					</button>
					<h2 class="modal-title">积分奖品信息</h2>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="updJFPrizes" method="POST">
						<input type="hidden" class="form-control" name="id" id="updJFPrizesId">
						<input type="hidden" class="form-control" name="type" id="updJFPrizesType">
						<div class="form-group">
							<label class="col-sm-3 control-label">奖品名称：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" name="name" maxlength='50'>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">奖品数量：</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" name="num" maxlength='11'>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">中奖积分：</label>
							<div class="col-sm-8">
									<input type="text" class="form-control" name="amount" id="amount" maxlength='8'	>
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-3 control-label">中奖概率：</label>
							<div class="col-sm-8">
								<div class="input-group">
									<input type="text" class="form-control" name="rate" id="rate" maxlength='8'
										value="0" style="text-align: right;"> <span
										class="input-group-addon">%</span>
								</div>
							</div>
						</div>
						
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" data-flg="0">保存</button>
				</div>
			</div>
		</div>
	</div>
	
	 <!-- 全局js -->
    <script src="${ctx}/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctx}/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="${ctx}/js/content.js?v=1.0.0"></script>
	<script src="${ctx}/js/plugins/layer/layer.min.js"></script>
    <script src="${ctx}/js/common.js"></script>
    <script src="${ctx}/js/plugins/toastr/toastr.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/jquery.validate.min.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
	toastr.options = {
			  "closeButton": false,
			  "debug": false,
			  "progressBar": false,
			  "positionClass": "toast-top-center",
			  "onclick": null,
			  "showDuration": "400",
			  "hideDuration": "1000",
			  "timeOut": "2000",
			  "extendedTimeOut": "1000",
			  "showEasing": "swing",
			  "hideEasing": "linear",
			  "showMethod": "fadeIn",
			  "hideMethod": "fadeOut"
			}
	//新增
	$("#addPrizesForm").validate({
		rules : {
			name : {
				required : true
			},
			num : {
				required : true,
				digits:true,
				min : 0
			},
			hb : {
				required : true,
				number:true,
				min : 1,
				max : 4999,
				towDot:true
			},
			jf : {
				required : true,
				digits: true,
				min: 0,
			},
			rate : {
				required : true,
				number:true,
				min : 0,
				max : 100
			}
		},
		messages : {
			name : {
				required : "请输入奖品名称"
			},
			num : {
				required : "请输入奖品数量",
				digits: "奖品数量为整数",
				min: "奖品数量不能小于0",
			},
			hb : {
				required : "请输入红包金额",
				number: "红包金额为不小于1的数字",
				min: "红包金额不能小于1",
				max:"红包金额不大于4999",
				towDot:"只能输入两位小数"
			},
			jf : {
				required : "请输入中奖积分",
				digits: "中奖积分为整数",
				min: "中奖积分不能小于0",
			},
			rate : {
				required : "请输入中奖概率",
				number: "中奖概率为整数",
				min: "中奖概率最小0",
				max: "中奖概率最大为100%"
			}
		}
	});
	//实物
	$("#updPrizes").validate({
		rules : {
			name : {
				required : true
			},
			num : {
				required : true,
				digits:true,
				min : 0
			},
			rate : {
				required : true,
				number:true,
				min : 0,
				max : 100
			}
		},
		messages : {
			name : {
				required : "请输入奖品名称"
			},
			num : {
				required : "请输入奖品数量",
				digits: "奖品数量为整数",
				min: "奖品数量不能小于0",
			},
			rate : {
				required : "请输入中奖概率",
				number: "中奖概率为整数",
				min: "中奖概率最小0",
				max: "中奖概率最大为100%"
			}
		}
	});
	
	//实物
	$("#swModal").on("click", "button", function(){
		if($(this).data('flg')=="0"){
			if($("#updPrizes").valid()){
				var type = $("#type_ option:selected").val();
				$.ajax({
					type:"POST",
					url: 'savePrizes',
					data:$("#updPrizes").serialize(),
					success:function(data){
						if(data.state == 1){
							window.location.href="./getPrizesConfig?type="+type;
						}else{
							toastr.error(data.message);
						}					
					},error: function(e){ 
						toastr.error("网络连接错误");
		            }
				});
				$('#swModal').modal("hide");
			}
		}    
	});
	//红包
	$("#updHBPrizes").validate({
		rules : {
			name : {
				required : true
			},
			num : {
				required : true,
				digits:true,
				min : 0
			},
			amount : {
				required : true,
				number:true,
				min : 1,
				max : 4999,
				towDot:true
			},
			rate : {
				required : true,
				number:true,
				min : 0,
				max : 100
			}
		},
		messages : {
			name : {
				required : "请输入奖品名称"
			},
			num : {
				required : "请输入奖品数量",
				digits: "奖品数量为整数",
				min: "奖品数量不能小于0",
			},
			amount : {
				required : "请输入红包金额",
				number: "红包金额为不小于1的数字",
				min: "红包金额不能小于1",
				max:"红包金额不大于4999",
				towDot:"只能输入两位小数"
			},
			rate : {
				required : "请输入中奖概率",
				number: "中奖概率为整数",
				min: "中奖概率最小0",
				max: "中奖概率最大为100%"
			}
		}
	});
	
	//红包
	$("#hbModal").on("click", "button", function(){
		if($(this).data('flg')=="0"){
			if($("#updHBPrizes").valid()){
				var type = $("#type_ option:selected").val();
				$.ajax({
					type:"POST",
					url: 'savePrizes',
					data:$("#updHBPrizes").serialize(),
					success:function(data){
						if(data.state == 1){
							window.location.href="./getPrizesConfig?type="+type;
						}else{
							toastr.error(data.message);
						}					
					},error: function(e){ 
						toastr.error("网络连接错误");
		            }
				});
				$('#hbModal').modal("hide");
			}
		}    
	});
	//积分
	$("#updJFPrizes").validate({
		rules : {
			name : {
				required : true
			},
			num : {
				required : true,
				digits:true,
				min : 0
			},
			amount : {
				required : true,
				digits:true,
				min : 0
			},
			rate : {
				required : true,
				number:true,
				min : 0,
				max : 100
			}
		},
		messages : {
			name : {
				required : "请输入奖品名称"
			},
			num : {
				required : "请输入奖品数量",
				digits: "奖品数量为整数",
				min: "奖品数量不能小于0",
			},
			amount : {
				required : "请输入中奖积分",
				digits: "中奖积分为整数",
				min: "中奖积分不能小于0",
			},
			rate : {
				required : "请输入中奖概率",
				number: "中奖概率为整数",
				min: "中奖概率最小0",
				max: "中奖概率最大为100%"
			}
		}
	});
	
	//更新信息
	$("#jfModal").on("click", "button", function(){
		if($(this).data('flg')=="0"){
			if($("#updJFPrizes").valid()){
				var type = $("#type_ option:selected").val();
				$.ajax({
					type:"POST",
					url: 'savePrizes',
					data:$("#updJFPrizes").serialize(),
					success:function(data){
						if(data.state == 1){
							window.location.href="./getPrizesConfig?type="+type;
						}else{
							toastr.error(data.message);
						}					
					},error: function(e){ 
						toastr.error("网络连接错误");
		            }
				});
				$('#jfModal').modal("hide");
			}
		}    
	});
	
	//定义只能输入两位小数的validate验证
	jQuery.validator.addMethod("towDot", function(value, element) {
		var bool = true;
		if (!isNaN(value)) {
			var dot = value.indexOf(".");
			if (dot != -1) {
				var dotCnt = value.substring(dot + 1, value.length);
				if (dotCnt.length > 2) {
					bool = false;
				}
			}
		}
		return bool;
	}, "只能输入两位小数");
	
	
	//删除信息
	$('#delModal').on("click", "button", function () {
		if($(this).data('flg')=="0"){
			var type = $("#type_ option:selected").val();
			var did = $("#delPrizesId").val();
			$.ajax({
				type:"POST",
				url: 'delPrizesById',
				data:{"id":did},
				success:function(data){
					if(data.state == 1){
						window.location.href="./getPrizesConfig?type="+type;
					}else{
						toastr.error(data.message);
					}
				},error: function(e){ 
					toastr.error(e);
	            }
			});
		}
		$('#delModal').modal("hide");
	});
	
	//新增奖品
	$("#addModal").on("click", "button", function(){
		if($(this).data('flg')=="0"){
			if($("#addPrizesForm").valid()){
				var type = $("#addType_ option:selected").val();
				$.ajax({
					type:"POST",
					url: 'addPrizes',
					data:$("#addPrizesForm").serialize(),
					success:function(data){
						if(data.state == 1){
							window.location.href="./getPrizesConfig?type="+type;
						}else{
							toastr.error(data.message);
						}					
					},error: function(e){ 
						toastr.error("网络连接错误");
		            }
				});
				$('#hbModal').modal("hide");
			}
		}    
	});
	
	findYYYConfig();
});

	function findYYYConfig(){
		$('#tableDiv').css('display','none');
		var type = $("#type_ option:selected").val();
		$.ajax({
			type : "POST",
			url : "findYYYConfig", //换成你要请求的action, paperId 是url参数
			data : {'type':type},
			dataType:"json",
			error : function(data) {
				$('table').css('dispaly','block');
				toastr.error("网络连接错误");
			},
			success : function(data) {
				if(data.state == 1){
					changeTable(type,data.data);
				}else{
					toastr.error(data.message);
				}
			}
		})
	}
	
	function delPrizes(id){
		$("#delPrizesId").attr("value",id);
		$('#delModal').modal("show");
	}
	
	function changeTable(type,data){
		var len = data.length;
		$('#tr').html('');
		$('#tbody').html('');
		var str = "";
        var bodyStr = "";
		if(type == 1){//实物
			str += '<th class="text-center">序号</th>'+
                '<th class="text-center">奖品名称</th>'+
                '<th class="text-center">奖品总数</th>'+
                '<th class="text-center">中奖概率(%)</th>'+
                '<th class="text-center">操作</th>';
			for(var i=0;i<len;i++){
				var p = data[i];
				var name = p.name_==null?"":p.name_;
				var num = p.num_==null?"":p.num_;
				var rate = p.rate_==null?"":p.rate_;
				bodyStr += '<tr><td>'+(i+1)+'</td><td>'+name+'</td><td>'+num+'</td><td>'+rate+'</td><td>'
				+'<button type="button" class="btn btn-success" onclick="showModel('+p.id+')">编辑</button> <button type="button" class="btn btn-danger" onclick="delPrizes('+p.id+')">删除</button></td></tr>';
			}
		}else if(type == 2){//红包
			str += '<th class="text-center">序号</th>'+
	            '<th class="text-center">奖品名称</th>'+
	            '<th class="text-center">奖品总数</th>'+
	            '<th class="text-center">红包金额(元)</th>'+
	            '<th class="text-center">中奖概率(%)</th>'+
	            '<th class="text-center">操作</th>';
			for(var i=0;i<len;i++){
				var p = data[i];
				var name = p.name_==null?"":p.name_;
				var amount = p.amount_==null?"":(p.amount_/100);
				var num = p.num_==null?"":p.num_;
				var rate = p.rate_==null?"":p.rate_;
				bodyStr += '<tr><td>'+(i+1)+'</td><td>'+name+'</td><td>'+num+'</td><td>'+amount+'</td><td>'+rate+'</td><td>'
				+'<button type="button" class="btn btn-success" onclick="showModel('+p.id+')">编辑</button> <button type="button" class="btn btn-danger" onclick="delPrizes('+p.id+')">删除</button></td></tr>';
			}
		}else if(type == 3){//积分
			str += '<th class="text-center">序号</th>'+
	            '<th class="text-center">奖品名称</th>'+
	            '<th class="text-center">奖品总数</th>'+
	            '<th class="text-center">中奖积分</th>'+
	            '<th class="text-center">中奖概率(%)</th>'+
	            '<th class="text-center">操作</th>';
			for(var i=0;i<len;i++){
				var p = data[i];
				var name = p.name_==null?"":p.name_;
				var amount = p.amount_==null?"":p.amount_;
				var num = p.num_==null?"":p.num_;
				var rate = p.rate_==null?"":p.rate_;
				bodyStr += '<tr><td>'+(i+1)+'</td><td>'+name+'</td><td>'+num+'</td><td>'+amount+'</td><td>'+rate+'</td><td>'
				+'<button type="button" class="btn btn-success" onclick="showModel('+p.id+')">编辑</button><button type="button" class="btn btn-danger" onclick="delPrizes('+p.id+')">删除</button></td></tr>';
			}
		}else{
			toastr.error("网络连接错误");
			return ;
		}
		$('#tr').html(str);
		$('#tbody').html(bodyStr);
		$('#tableDiv').css('display','block');
	}
	
	function showModel(id){
		var type = $("#type_ option:selected").val();
		$.ajax({
			type : "POST",
			url : "findPrizesById", //换成你要请求的action, paperId 是url参数
			data : {'id':id},
			dataType:"json",
			error : function(data) {
				toastr.error("网络连接错误");
			},
			success : function(data) {
				if(data.state == 1){
					changeModel(type,data.data);
				}else{
					toastr.error(data.message);
				}
			}
		})
		
	}
	
	function changeModel(type,data){
		if(type == 1){//实物
			$("#updPrizesId").attr("value",data.id);
			$("#updPrizesType").attr("value",data.type_);
			$("#swModal :text")[0].value = data.name_;
			$("#swModal :text")[1].value = data.num_;
			$("#swModal :text")[2].value = data.rate_;
			$('#swModal').modal("show");
		}else if(type == 2){//红包
			$("#updHBPrizesId").attr("value",data.id);
			$("#updHBPrizesType").attr("value",data.type_);
			$("#hbModal :text")[0].value = data.name_;
			$("#hbModal :text")[1].value = data.num_;
			$("#hbModal :text")[2].value = data.amount_/100;
			$("#hbModal :text")[3].value = data.rate_;
			$('#hbModal').modal("show");
		}else if(type == 3){//积分
			$("#updJFPrizesId").attr("value",data.id);
			$("#updJFPrizesType").attr("value",data.type_);
			$("#jfModal :text")[0].value = data.name_;
			$("#jfModal :text")[1].value = data.num_;
			$("#jfModal :text")[2].value = data.amount_;
			$("#jfModal :text")[3].value = data.rate_;
			$('#jfModal').modal("show");
		}else{
			toastr.error("网络连接错误");
		}
	}
    
	/* function delPrizes(id){
		$.ajax({
			type : "POST",
			url : "delPrizesById", //换成你要请求的action, paperId 是url参数
			data : {'id':id},
			dataType:"json",
			error : function(data) {
				toastr.error("网络连接错误");
			},
			success : function(data) {
				if(data.state == 1){
					toastr.success(data.success);
					window.location.reload();
				}else{
					toastr.error(data.message);
				}
			}
		})
	} */
	
	function addPrizesModal(){		
		$('#addModal').modal("show");
	}
	
	function changeAddModal(){
		var type = $("#addType_ option:selected").val();
		if(type == 1){//实物
			$("#hb").css("display","none");
			$("#jf").css("display","none");
			$("#addModal :text")[2].value = "";
			$("#addModal :text")[3].value = "";
		}else if(type == 2){//红包
			$("#hb").css("display","block");
			$("#jf").css("display","none");
			$("#addModal :text")[3].value = "";
		}else if(type == 3){//积分			
			$("#hb").css("display","none");
			$("#jf").css("display","block");
			$("#addModal :text")[2].value = "";
		}else{
			toastr.error("网络连接错误");
			return;
		}
	}

</script>
</body>
</html>